package com.charm.bulkcomponent.ui.fragment

import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.alibaba.android.arouter.facade.annotation.Route
import com.charm.bulkcomponent.R
import com.charm.bulkcomponent.adapter.UserCenterAdapter
import com.charm.bulkcomponent.adapter.UserCenterDecoration
import com.charm.bulkcomponent.constract.UserCenterView
import com.charm.bulkcomponent.constract.presenter.UserCenterPresenter
import com.charm.bulkcomponent.entity.UserCenterEntity
import com.charm.codes.imageLoad.XGlide
import com.charm.codes.mvp.factory.CreatePresenter
import com.charm.codes.mvp.view.AbstractFragment


/**
 * Created by tools on 2018/1/19.
 */
@Route(path = "/common/userCenter")
@CreatePresenter(UserCenterPresenter::class)
class UserCenterFragment : AbstractFragment<UserCenterView, UserCenterPresenter>(), UserCenterView {
    lateinit var rv: RecyclerView
    lateinit var header: ImageView
    lateinit var name: TextView
    lateinit var company: TextView
    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        var rootView = inflater!!.inflate(R.layout.activity_user_center, container, false)
        initView(rootView)
        return rootView
    }


    override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initData()
    }

    private fun initView(rootView: View?) {
        header = rootView!!.findViewById(R.id.header)
        name = rootView!!.findViewById(R.id.name)
        company = rootView!!.findViewById(R.id.company)
        rv = rootView!!.findViewById(R.id.rv)
    }

    private fun initData() {
        XGlide.getInstance().with(context)
                .load("http://img4.duitang.com/uploads/item/201303/22/20130322220025_Q4HNi.thumb.600_0.jpeg")
                .placeholder(com.charm.information.R.drawable.bg_block)
                .error(com.charm.information.R.drawable.bg_block)
                .into(header)
                .displayCircleImage()
        name.text = "谭锐"
        company.text = "那卡蒂斯"
        var userCenter = ArrayList<UserCenterEntity>()
        userCenter.add(UserCenterEntity(0, "消息中心", "0", ""))
        userCenter.add(UserCenterEntity(0, "收藏集", "0", ""))
        userCenter.add(UserCenterEntity(0, "我喜欢的", "0", ""))
        userCenter.add(UserCenterEntity(0, "阅读过的文章", "0", ""))
        rv.layoutManager = LinearLayoutManager(context)
        rv.addItemDecoration(UserCenterDecoration())
        rv.adapter = UserCenterAdapter(userCenter)
    }
}